package com.ruoyi.web.controller.V2.web.conntroller.apiSms;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.V2.inter.mapper.SalePartnerMapper;
import com.ruoyi.system.gen.IGenAPI;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.outto.goods.impl.ApiSmsService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author lz
 * @version 1.0
 * @date 2022/5/10 18:34
 */
@RestController
@RequestMapping("open/api/sms")
public class ApiSmsController {

    @Resource
    SalePartnerMapper salePartnerMapper;
    @Autowired
    ApiSmsService apiSmsService;

    /**
     * 过盼之的验证码
     */
    @GetMapping("/panzhi")
    public AjaxResult panzhi(@RequestParam Map<String,Object> params) {

        String phone = MapUtils.getString(params, "phone");

        List<SalePartner> salePartners = salePartnerMapper.selectSalePartnerByPhone(phone);
        SalePartner salePartner = salePartners.get(0);
        String msg = MapUtils.getString(params, "msg");
        System.out.println("msg=" + msg);
        System.out.println("phone=" + phone);
        if (msg.contains("盼之代售") && msg.contains("打死不要")){
            apiSmsService.toPanzhi(msg,salePartner);
        }
        return AjaxResult.success();
    }

}
